package util.loaders;

import java.io.IOException;
import java.io.InputStream;

import net.ByteBuffer;

/**
 * 
 * Use this when your game is running from an executable jar file.
 * 
 * In this case, all resources are loaded internally from a single
 * jar file.
 * 
 * @author Jason
 *
 */
public class InternalJarLoader extends DataLoader {

	protected final Class<?> loader;
	protected final ByteBuffer bb = new ByteBuffer();
	
	/**
	 * Input a class which will be used to load the resources.
	 * 
	 * If your resources are in util/data/
	 * make sure that the given class is in the
	 * util directory.
	 */
	public InternalJarLoader(Class<?> loader){
		if(loader == null)
			throw new RuntimeException("Loader cannot be null.");
		this.loader = loader;
	}
	
	@Override
	public InputStream load(String dataName) throws IOException {
		InputStream is = loader.getResourceAsStream(dataName);
		return is;
	}

}
